// pages/activity/my/my.js
let utilApp = require('../../../../utils/app');
const { regeneratorRuntime } = global

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    status:0,
    count:0,
    uid:0,
    his:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  toggle:function(e){
    let userInfo = wx.getStorageSync('userInfo');
    this.setData({ 
      currentTab: e.currentTarget.dataset.current
    }) 
    if (e.currentTarget.dataset.current==0){
      this.getItem('User/myItem', { uid: userInfo.uId }, this)
    }else{
      this.getIn('User/myIn', { openId: userInfo.openId }, this)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let userInfo = wx.getStorageSync('userInfo');
    this.getItem('User/myItem', {uid:userInfo.uId},this)
  }, 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
  async getItem(url, params,that){
    let res = await utilApp.doPost(url, params);
    if (res.data.myItem.status==1){
      that.setData({
        status:1
      })
    }else{
      that.setData({
        count: 3 - res.data.myItem.count
      })
    } 
  },
  async getIn(url, params, that) { 
    this.setData({
      status: 0,
    })
    let res = await utilApp.doPost(url, params);
    if (res.data.myIn.uid){
      if (res.data.myIn.status == 1) {
        that.setData({
          status: 1,
          uid: res.data.myIn.uid, 
          his: 1,
        })   
      } else {
        that.setData({
          count: 3 - res.data.myIn.count,
          uid: res.data.myIn.uid,
          his: 1  
        }) 
      }
    }
  }, 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
  gotoMy(){
    wx.navigateTo({
      url: '/pages/activity/combination/index/index',
    })
  },
  gotoHis() {
    wx.navigateTo({
      url: '/pages/activity/combination/index/index?uid=' + this.data.uid,
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */

})
